package simpleTaskDispatcher.model.tasks;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import simpleTaskDispatcher.model.enums.TaskPlacement;

public class DelayedTasks {

	private final List<ITask> tasks;
	
	private final Collection<ITask> dependencies;
	
	private int numberOfDependencies;

	private final TaskPlacement placement;

	public DelayedTasks(ITask task, ITask dependency, TaskPlacement placement) {
		this(Collections.singletonList(task), Collections.singletonList(dependency), placement);
	}
	
	public DelayedTasks(ITask task, Collection<ITask> dependencies, TaskPlacement placement) {
		this(Collections.singletonList(task), dependencies, placement);
	}
	
	public DelayedTasks(List<ITask> tasks, ITask dependency, TaskPlacement placement) {
		this(tasks, Collections.singletonList(dependency), placement);
	}
	
	public DelayedTasks(List<ITask> tasks, Collection<ITask> dependencies, TaskPlacement placement) {
		super();
		this.tasks = tasks;
		this.dependencies = dependencies;
		this.numberOfDependencies = dependencies.size();
		this.placement = placement;
	}

	public void decrementDependencies() {
		numberOfDependencies --;
	}
	
	public boolean areDependenciesFinished() {
		return numberOfDependencies == 0;
	}
	
	public List<ITask> getTasks() {
		return tasks;
	}

	public TaskPlacement getPlacement() {
		return placement;
	}
	
	public Collection<ITask> getDependencies() {
		return dependencies;
	}
	
}
